/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fhv.itb.ec.fruitshop;

import java.util.Vector;
import javax.ejb.EJB;

/**
 *
 * @author Malcolm
 */
public class FruitClient {
    

    /**
     * @param args the command line arguments
     */
    @EJB private static FruitBasketRemote fbr;
    public static void main(String[] args) {

        Vector<Long> shopIDs = fbr.getShopList();

        System.out.println("Available shops:");

        for (Long id : shopIDs) {
            System.out.println("Shop " + id);
        }

        fbr.selectShop(32);
        System.out.println("Selected shop " + fbr.getShopID());

        System.out.println("Available fruits:");

        Vector<String> fruits = fbr.listAvailableFruits();

        if (fruits != null && !fruits.isEmpty()) {

            for (String f : fruits) {
                System.out.println(f);
            }
            
            fbr.addFruit(14);
            System.out.println("Adding fruit 14 to basket");
            fbr.addFruit(14);
            System.out.println("Adding fruit 14 to basket");
            fbr.addFruit(7);
            System.out.println("Adding fruit 7 to basket");
        }
        
        int fruitsInBasket = fbr.getNumOfFruits();
        System.out.println("The basket contains " + fruitsInBasket + " fruits");
        
        double basketCost = fbr.getCostOfFruits();
        System.out.println("The fruits in basket cost " + basketCost + " EUR");
        
        String basketItems = fbr.getContents();
        System.out.println("The following Fruits are in the basket:");
        System.out.println(basketItems);
        
        if (fbr.removeFruit(14) == true) {
            System.out.println("Removed 1 fruit 14 from basket");
        }

        int fruitsInBasket2 = fbr.getNumOfFruits();
        System.out.println("The basket contains " + fruitsInBasket2 + " fruits");
        
        basketItems = fbr.getContents();
        System.out.println("The following Fruits are in the basket:");
        System.out.println(basketItems);

        fbr.selectShop(94);
        System.out.println("Selected shop " + fbr.getShopID());

        System.out.println("Available fruits:");

        Vector<String> fruits1 = fbr.listAvailableFruits();
        
        if (fruits1 != null && !fruits1.isEmpty()) {

            for (String f : fruits1) {
                System.out.println(f);
            }
            
            fbr.addFruit(90);
            System.out.println("Adding fruit 90 to basket");
            fbr.addFruit(81);
            System.out.println("Adding fruit 81 to basket");
            fbr.addFruit(83);
            System.out.println("Adding fruit 83 to basket");
             
        }
        
        basketItems = fbr.getContents();
        System.out.println("The following Fruits are in the basket:");
        System.out.println(basketItems);
        
        int fruitsInBasket1 = fbr.getNumOfFruits();
        System.out.println("The basket contains " + fruitsInBasket1 + " fruits");
        
        double basketCost1 = fbr.getCostOfFruits();
        System.out.println("The fruits in basket cost " + basketCost1 + " EUR");
        
    }

}
